Nightly Per-Antenna Quality Summary Notebook¶

Josh Dillon, Last Revised February 2021

This notebooks brings together as much information as possible from ant_metrics, auto_metrics and redcal to help figure out which antennas are working properly and summarizes it in a single giant table. It is meant to be lightweight and re-run as often as necessary over the night, so it can be run when any of those is done and then be updated when another one completes.

Contents:¶

  • Table 1: Overall Array Health
  • Table 2: RTP Per-Antenna Metrics Summary Table
  • Figure 1: Array Plot of Flags and A Priori Statuses
In [1]:
import os
os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE'
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
pd.set_option('display.max_rows', 1000)
from hera_qm.metrics_io import load_metric_file
from hera_cal import utils, io, redcal
import glob
import h5py
from copy import deepcopy
from IPython.display import display, HTML
from hera_notebook_templates.utils import status_colors
from hera_mc import mc
from pyuvdata import UVData

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
display(HTML("<style>.container { width:100% !important; }</style>"))
In [2]:
# If you want to run this notebook locally, copy the output of the next cell into the first few lines of this cell.

# JD = "2459122"
# data_path = '/lustre/aoc/projects/hera/H4C/2459122'
# ant_metrics_ext = ".ant_metrics.hdf5"
# redcal_ext = ".maybe_good.omni.calfits"
# nb_outdir = '/lustre/aoc/projects/hera/H4C/h4c_software/H4C_Notebooks/_rtp_summary_'
# good_statuses = "digital_ok,calibration_maintenance,calibration_triage,calibration_ok"
# os.environ["JULIANDATE"] = JD
# os.environ["DATA_PATH"] = data_path
# os.environ["ANT_METRICS_EXT"] = ant_metrics_ext
# os.environ["REDCAL_EXT"] = redcal_ext
# os.environ["NB_OUTDIR"] = nb_outdir
# os.environ["GOOD_STATUSES"] = good_statuses
In [3]:
# Use environment variables to figure out path to data
JD = os.environ['JULIANDATE']
data_path = os.environ['DATA_PATH']
ant_metrics_ext = os.environ['ANT_METRICS_EXT']
redcal_ext = os.environ['REDCAL_EXT']
nb_outdir = os.environ['NB_OUTDIR']
good_statuses = os.environ['GOOD_STATUSES']
print(f'JD = "{JD}"')
print(f'data_path = "{data_path}"')
print(f'ant_metrics_ext = "{ant_metrics_ext}"')
print(f'redcal_ext = "{redcal_ext}"')
print(f'nb_outdir = "{nb_outdir}"')
print(f'good_statuses = "{good_statuses}"')
JD = "2459764"
data_path = "/mnt/sn1/2459764"
ant_metrics_ext = ".ant_metrics.hdf5"
redcal_ext = ".known_good.omni.calfits"
nb_outdir = "/home/obs/src/H5C_Notebooks/_rtp_summary_"
good_statuses = ""
In [4]:
from astropy.time import Time
utc = Time(JD, format='jd').datetime
print(f'Date: {utc.month}-{utc.day}-{utc.year}')
Date: 7-3-2022
In [5]:
# Per-season options
def ant_to_report_url(ant):
    return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/antenna_report/antenna_{ant}_report.html'

Load Auto Metrics¶

In [6]:
use_auto_metrics = False

# find the auto_metrics file
glob_str = os.path.join(data_path, f'zen.{JD}*.auto_metrics.h5')
auto_metrics_file = sorted(glob.glob(glob_str))

# if it exists, load and extract relevant information
if len(auto_metrics_file) > 0:
    auto_metrics_file = auto_metrics_file[0]
    print(f'Found auto_metrics results file at {auto_metrics_file}.')
    
    auto_metrics = load_metric_file(auto_metrics_file)
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
    auto_ex_ants = auto_metrics['ex_ants']['r2_ex_ants']
    
    use_auto_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping auto_metrics.')
Found auto_metrics results file at /mnt/sn1/2459764/zen.2459764.21977.sum.auto_metrics.h5.

Load Ant Metrics¶

In [7]:
use_ant_metrics = False

# get a list of all ant_metrics files
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{ant_metrics_ext}')
ant_metrics_files = sorted(glob.glob(glob_str))

# if they exist, load as many of them as possible
if len(ant_metrics_files) > 0:
    print(f'Found {len(ant_metrics_files)} ant_metrics files matching glob {glob_str}')
    ant_metrics_apriori_exants = {}
    ant_metrics_xants_dict = {}
    ant_metrics_dead_ants_dict = {}
    ant_metrics_crossed_ants_dict = {}
    ant_metrics_dead_metrics = {}
    ant_metrics_crossed_metrics = {}
    dead_cuts = {}
    crossed_cuts = {}
    for amf in ant_metrics_files:
        with h5py.File(amf, "r") as infile: # use h5py directly since it's much faster than load_metric_file
            # get out results for this file
            dead_cuts[amf] = infile['Metrics']['dead_ant_cut'][()]
            crossed_cuts[amf] = infile['Metrics']['cross_pol_cut'][()]
            xants = infile['Metrics']['xants'][:]
            dead_ants = infile['Metrics']['dead_ants'][:]
            crossed_ants = infile['Metrics']['crossed_ants'][:]        
            try:
                # look for ex_ants in history
                ex_ants_string = infile['Header']['history'][()].decode()
                ex_ants_string = ex_ants_string.split('--apriori_xants')[1]
                ex_ants_string = ex_ants_string.split('--')[0].strip()
            except:
                ex_ants_string = ''
                    
            # This only works for the new correlation-matrix-based ant_metrics
            if 'corr' in infile['Metrics']['final_metrics'] and 'corrXPol' in infile['Metrics']['final_metrics']:
                ant_metrics_dead_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corr'][ant][()]
                                                 for ant in infile['Metrics']['final_metrics']['corr']}
                ant_metrics_crossed_metrics[amf] = {eval(ant): infile['Metrics']['final_metrics']['corrXPol'][ant][()]
                                                    for ant in infile['Metrics']['final_metrics']['corrXPol']}                       
            else:
                raise(KeywordError)
        
        # organize results by file
        ant_metrics_xants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in xants]
        ant_metrics_dead_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in dead_ants]
        ant_metrics_crossed_ants_dict[amf] = [(int(ant[0]), ant[1].decode()) for ant in crossed_ants]
        ant_metrics_apriori_exants[amf] = [int(ant) for ant in ex_ants_string.split()]
    
    dead_cut = np.median(list(dead_cuts.values()))
    crossed_cut = np.median(list(crossed_cuts.values()))
        
    use_ant_metrics = True
else:
    print(f'No files found matching glob {glob_str}. Skipping ant_metrics.')
Found 1937 ant_metrics files matching glob /mnt/sn1/2459764/zen.2459764.?????.sum.ant_metrics.hdf5

Load chi^2 info from redcal¶

In [8]:
use_redcal = False
glob_str = os.path.join(data_path, f'zen.{JD}.?????.sum{redcal_ext}')

redcal_files = sorted(glob.glob(glob_str))
if len(redcal_files) > 0:
    print(f'Found {len(redcal_files)} ant_metrics files matching glob {glob_str}')
    post_redcal_ant_flags_dict = {}
    flagged_by_redcal_dict = {}
    cspa_med_dict = {}
    for cal in redcal_files:
        hc = io.HERACal(cal)
        _, flags, cspa, chisq = hc.read()
        cspa_med_dict[cal] = {ant: np.nanmedian(cspa[ant], axis=1) for ant in cspa}

        post_redcal_ant_flags_dict[cal] = {ant: np.all(flags[ant]) for ant in flags}
        # check history to distinguish antennas flagged going into redcal from ones flagged during redcal
        tossed_antenna_lines =  hc.history.replace('\n','').split('Throwing out antenna ')[1:]
        flagged_by_redcal_dict[cal] = sorted([int(line.split(' ')[0]) for line in tossed_antenna_lines])
        
    use_redcal = True
else:
    print(f'No files found matching glob {glob_str}. Skipping redcal chisq.')
Found 151 ant_metrics files matching glob /mnt/sn1/2459764/zen.2459764.?????.sum.known_good.omni.calfits

Figure out some general properties¶

In [9]:
# Parse some general array properties, taking into account the fact that we might be missing some of the metrics
ants = []
pols = []
antpol_pairs = []

if use_auto_metrics:
    ants = sorted(set(bl[0] for bl in auto_metrics['modzs']['r2_shape_modzs']))
    pols = sorted(set(bl[2] for bl in auto_metrics['modzs']['r2_shape_modzs']))
if use_ant_metrics:
    antpol_pairs = sorted(set([antpol for dms in ant_metrics_dead_metrics.values() for antpol in dms.keys()]))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))
if use_redcal:
    antpol_pairs = sorted(set([ant for cspa in cspa_med_dict.values() for ant in cspa.keys()]) | set(antpol_pairs))
    antpols = sorted(set(antpol[1] for antpol in antpol_pairs))
    ants = sorted(set(antpol[0] for antpol in antpol_pairs) | set(ants))
    pols = sorted(set(utils.join_pol(ap, ap) for ap in antpols) | set(pols))

# Figure out remaining antennas not in data and also LST range
data_files = sorted(glob.glob(os.path.join(data_path, 'zen.*.sum.uvh5')))
hd = io.HERAData(data_files[0])
unused_ants = [ant for ant in hd.antpos if ant not in ants]    
hd_last = io.HERAData(data_files[-1])

Load a priori antenna statuses and node numbers¶

In [10]:
# try to load a priori antenna statusesm but fail gracefully if this doesn't work.
a_priori_statuses = {ant: 'Not Found' for ant in ants}
nodes = {ant: np.nan for ant in ants + unused_ants}
try:
    from hera_mc import cm_hookup

    # get node numbers
    hookup = cm_hookup.get_hookup('default')
    for ant_name in hookup:
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in nodes:
            if hookup[ant_name].get_part_from_type('node')['E<ground'] is not None:
                nodes[ant] = int(hookup[ant_name].get_part_from_type('node')['E<ground'][1:])
    
    # get apriori antenna status
    for ant_name, data in hookup.items():
        ant = int("".join(filter(str.isdigit, ant_name)))
        if ant in a_priori_statuses:
            a_priori_statuses[ant] = data.apriori

except Exception as err:
    print(f'Could not load node numbers and a priori antenna statuses.\nEncountered {type(err)} with message: {err}')

Summarize auto metrics¶

In [11]:
if use_auto_metrics:
    # Parse modzs
    modzs_to_check = {'Shape': 'r2_shape_modzs', 'Power': 'r2_power_modzs', 
                      'Temporal Variability': 'r2_temp_var_modzs', 'Temporal Discontinuties': 'r2_temp_diff_modzs'}
    worst_metrics = []
    worst_zs = []
    all_modzs = {}
    binary_flags = {rationale: [] for rationale in modzs_to_check}

    for ant in ants:
        # parse modzs and figure out flag counts
        modzs = {f'{pol} {rationale}': auto_metrics['modzs'][dict_name][(ant, ant, pol)] 
                 for rationale, dict_name in modzs_to_check.items() for pol in pols}
        for pol in pols:
            for rationale, dict_name in modzs_to_check.items():
                binary_flags[rationale].append(auto_metrics['modzs'][dict_name][(ant, ant, pol)] > mean_round_modz_cut)

        # parse out all metrics for dataframe
        for k in modzs:
            col_label = k + ' Modified Z-Score'
            if col_label in all_modzs:
                all_modzs[col_label].append(modzs[k])
            else:
                all_modzs[col_label] = [modzs[k]]
                
    mean_round_modz_cut = auto_metrics['parameters']['mean_round_modz_cut']
else:
    mean_round_modz_cut = 0

Summarize ant metrics¶

In [12]:
if use_ant_metrics:
    a_priori_flag_frac = {ant: np.mean([ant in apxa for apxa in ant_metrics_apriori_exants.values()]) for ant in ants}
    dead_ant_frac = {ap: {ant: np.mean([(ant, ap) in das for das in ant_metrics_dead_ants_dict.values()])
                                 for ant in ants} for ap in antpols}
    crossed_ant_frac = {ant: np.mean([np.any([(ant, ap) in cas for ap in antpols])
                                      for cas in ant_metrics_crossed_ants_dict.values()]) for ant in ants}
    ant_metrics_xants_frac_by_antpol = {antpol: np.mean([antpol in amx for amx in ant_metrics_xants_dict.values()]) for antpol in antpol_pairs}
    ant_metrics_xants_frac_by_ant = {ant: np.mean([np.any([(ant, ap) in amx for ap in antpols])
                                     for amx in ant_metrics_xants_dict.values()]) for ant in ants}
    average_dead_metrics = {ap: {ant: np.nanmean([dm.get((ant, ap), np.nan) for dm in ant_metrics_dead_metrics.values()]) 
                                 for ant in ants} for ap in antpols}
    average_crossed_metrics = {ant: np.nanmean([cm.get((ant, ap), np.nan) for ap in antpols 
                                                for cm in ant_metrics_crossed_metrics.values()]) for ant in ants}
else:
    dead_cut = 0.4
    crossed_cut = 0.0

Summarize redcal chi^2 metrics¶

In [13]:
if use_redcal:
    cspa = {ant: np.nanmedian(np.hstack([cspa_med_dict[cal][ant] for cal in redcal_files])) for ant in antpol_pairs}
    redcal_prior_flag_frac = {ant: np.mean([np.any([afd[ant, ap] and not ant in flagged_by_redcal_dict[cal] for ap in antpols])
                                            for cal, afd in post_redcal_ant_flags_dict.items()]) for ant in ants}
    redcal_flagged_frac = {ant: np.mean([ant in fbr for fbr in flagged_by_redcal_dict.values()]) for ant in ants}

Get FEM switch states¶

In [14]:
HHautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.sum.autos.uvh5"))
diffautos = sorted(glob.glob(f"{data_path}/zen.{JD}.*.diff.autos.uvh5"))

try:
    db = mc.connect_to_mc_db(None)
    session = db.sessionmaker()
    startJD = float(HHautos[0].split('zen.')[1].split('.sum')[0])
    stopJD = float(HHautos[-1].split('zen.')[1].split('.sum')[0])
    startTime = Time(startJD,format='jd')
    stopTime = Time(stopJD,format='jd')
    res = session.get_antenna_status(starttime=startTime, stoptime=stopTime)
    fem_switches = {}
    if len(res) == 0:
        femState = None
    else:
        for antpol in res:
            fem_switches[(antpol.antenna_number, antpol.antenna_feed_pol)] = antpol.fem_switch
    femState = (max(set(list(fem_switches.values())), key = list(fem_switches.values()).count)) 
except Exception as e:
    print(e)
    femState = None

Find X-engine Failures¶

In [15]:
read_inds = [1, len(HHautos)//2, -2]
x_status = [1,1,1,1,1,1,1,1]
s = UVData()
s.read(HHautos[1])

nants = len(s.get_ants())
freqs = s.freq_array[0]*1e-6
nfreqs = len(freqs)

antCon = {a: None for a in ants}
rightAnts = []
for i in read_inds:
    s = UVData()
    d = UVData()
    s.read(HHautos[i])
    d.read(diffautos[i])
    for pol in [0,1]:
        sm = np.abs(s.data_array[:,0,:,pol])
        df = np.abs(d.data_array[:,0,:,pol])
        sm = np.r_[sm, np.nan + np.zeros((-len(sm) % nants,len(freqs)))]
        sm = np.nanmean(sm.reshape(-1,nants,nfreqs),axis=1)
        df = np.r_[df, np.nan + np.zeros((-len(df) % nants,len(freqs)))]
        df = np.nanmean(df.reshape(-1,nants,nfreqs),axis=1)

        evens = (sm + df)/2
        odds = (sm - df)/2
        rat = np.divide(evens,odds)
        rat = np.nan_to_num(rat)
        for xbox in range(0,8):
            xavg = np.nanmean(rat[:,xbox*192:(xbox+1)*192],axis=1)
            if np.nanmax(xavg)>1.5 or np.nanmin(xavg)<0.5:
                x_status[xbox] = 0
    for ant in ants:
        for pol in ["xx", "yy"]:
            if antCon[ant] is False:
                continue
            spectrum = s.get_data(ant, ant, pol)
            stdev = np.std(spectrum)
            med = np.median(np.abs(spectrum))
            if (femState == "load" or femState == 'noise') and 80000 < stdev <= 4000000 and antCon[ant] is not False:
                antCon[ant] = True
            elif femState == "antenna" and stdev > 500000 and med > 950000 and antCon[ant] is not False:
                antCon[ant] = True
            else:
                antCon[ant] = False
            if np.min(np.abs(spectrum)) < 100000:
                antCon[ant] = False
for ant in ants:
    if antCon[ant] is True:
        rightAnts.append(ant)
            
x_status_str = ''
for i,x in enumerate(x_status):
    if x==0:
        x_status_str += '\u274C '
    else:
        x_status_str += '\u2705 '

Build Overall Health DataFrame¶

In [16]:
def comma_sep_paragraph(vals, chars_per_line=40):
    outstrs = []
    for val in vals:
        if (len(outstrs) == 0) or (len(outstrs[-1]) > chars_per_line):
            outstrs.append(str(val))
        else:
            outstrs[-1] += ', ' + str(val)
    return ',<br>'.join(outstrs)
In [17]:
# Time data
to_show = {'JD': [JD]}
to_show['Date'] = f'{utc.month}-{utc.day}-{utc.year}'
to_show['LST Range'] = f'{hd.lsts[0] * 12 / np.pi:.3f} -- {hd_last.lsts[-1] * 12 / np.pi:.3f} hours'

# X-engine status
to_show['X-Engine Status'] = x_status_str

# Files
to_show['Number of Files'] = len(data_files)

# Antenna Calculations
to_show['Total Number of Antennas'] = len(ants)

to_show[' '] = ''
to_show['OPERATIONAL STATUS SUMMARY'] = ''

status_count = {status: 0 for status in status_colors}
for ant, status in a_priori_statuses.items():
    if status in status_count:
        status_count[status] = status_count[status] + 1
    else:
        status_count[status] = 1
to_show['Antenna A Priori Status Count'] = '<br>'.join([f'{status}: {status_count[status]}' for status in status_colors if status in status_count and status_count[status] > 0])

to_show['Commanded Signal Source'] = femState
to_show['Antennas in Commanded State'] = f'{len(rightAnts)} / {len(ants)} ({len(rightAnts) / len(ants):.1%})'

if use_ant_metrics:
    to_show['Cross-Polarized Antennas'] = ', '.join([str(ant) for ant in ants if (np.max([dead_ant_frac[ap][ant] for ap in antpols]) + crossed_ant_frac[ant] == 1) 
                                                                                 and (crossed_ant_frac[ant] > .5)])

# Node calculations
nodes_used = set([nodes[ant] for ant in ants if np.isfinite(nodes[ant])])
to_show['Total Number of Nodes'] = len(nodes_used)
if use_ant_metrics:
    node_off = {node: True for node in nodes_used}
    not_correlating = {node: True for node in nodes_used}
    for ant in ants:
        for ap in antpols:
            if np.isfinite(nodes[ant]):
                if np.isfinite(average_dead_metrics[ap][ant]):
                    node_off[nodes[ant]] = False
                if dead_ant_frac[ap][ant] < 1:
                    not_correlating[nodes[ant]] = False
    to_show['Nodes Registering 0s'] = ', '.join([f'N{n:02}' for n in sorted([node for node in node_off if node_off[node]])])
    to_show['Nodes Not Correlating'] = ', '.join([f'N{n:02}' for n in sorted([node for node in not_correlating if not_correlating[node] and not node_off[node]])])

# Pipeline calculations    
to_show['  '] = ''
to_show['NIGHTLY ANALYSIS SUMMARY'] = ''
    
all_flagged_ants = []
if use_ant_metrics:
    to_show['Ant Metrics Done?'] = '\u2705'
    ant_metrics_flagged_ants = [ant for ant in ants if ant_metrics_xants_frac_by_ant[ant] > 0]
    all_flagged_ants.extend(ant_metrics_flagged_ants)
    to_show['Ant Metrics Flagged Antennas'] = f'{len(ant_metrics_flagged_ants)} / {len(ants)} ({len(ant_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Ant Metrics Done?'] = '\u274C'
if use_auto_metrics:
    to_show['Auto Metrics Done?'] = '\u2705'
    auto_metrics_flagged_ants = [ant for ant in ants if ant in auto_ex_ants]
    all_flagged_ants.extend(auto_metrics_flagged_ants)    
    to_show['Auto Metrics Flagged Antennas'] = f'{len(auto_metrics_flagged_ants)} / {len(ants)} ({len(auto_metrics_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Auto Metrics Done?'] = '\u274C'
if use_redcal:
    to_show['Redcal Done?'] = '\u2705'    
    redcal_flagged_ants = [ant for ant in ants if redcal_flagged_frac[ant] > 0]
    all_flagged_ants.extend(redcal_flagged_ants)    
    to_show['Redcal Flagged Antennas'] = f'{len(redcal_flagged_ants)} / {len(ants)} ({len(redcal_flagged_ants) / len(ants):.1%})' 
else:
    to_show['Redcal Done?'] = '\u274C' 
to_show['Never Flagged Antennas'] = f'{len(ants) - len(set(all_flagged_ants))} / {len(ants)} ({(len(ants) - len(set(all_flagged_ants))) / len(ants):.1%})'

# Count bad antennas with good statuses and vice versa
n_apriori_good = len([ant for ant in ants if a_priori_statuses[ant] in good_statuses.split(',')])
apriori_good_flagged = []
aprior_bad_unflagged = []
for ant in ants:
    if ant in set(all_flagged_ants) and a_priori_statuses[ant] in good_statuses.split(','):
        apriori_good_flagged.append(ant)
    elif ant not in set(all_flagged_ants) and a_priori_statuses[ant] not in good_statuses.split(','):
        aprior_bad_unflagged.append(ant)
to_show['A Priori Good Antennas Flagged'] = f'{len(apriori_good_flagged)} / {n_apriori_good} total a priori good antennas:<br>' + \
                                            comma_sep_paragraph(apriori_good_flagged)
to_show['A Priori Bad Antennas Not Flagged'] = f'{len(aprior_bad_unflagged)} / {len(ants) - n_apriori_good} total a priori bad antennas:<br>' + \
                                            comma_sep_paragraph(aprior_bad_unflagged)

# Apply Styling
df = pd.DataFrame(to_show)
divider_cols = [df.columns.get_loc(col) for col in ['NIGHTLY ANALYSIS SUMMARY', 'OPERATIONAL STATUS SUMMARY']]
try:
    to_red_columns = [df.columns.get_loc(col) for col in ['Cross-Polarized Antennas', 'Nodes Registering 0s', 
                                                          'Nodes Not Correlating', 'A Priori Good Antennas Flagged']]
except:
    to_red_columns = []
def red_specific_cells(x):
    df1 = pd.DataFrame('', index=x.index, columns=x.columns)
    for col in to_red_columns:
        df1.iloc[col] = 'color: red'
    return df1

df = df.T
table = df.style.hide_columns().apply(red_specific_cells, axis=None)
for col in divider_cols:
    table = table.set_table_styles([{"selector":f"tr:nth-child({col+1})", "props": [("background-color", "black"), ("color", "white")]}], overwrite=False)

Table 1: Overall Array Health¶

In [18]:
HTML(table.render())
Out[18]:
JD 2459764
Date 7-3-2022
LST Range 13.482 -- 0.304 hours
X-Engine Status ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
Number of Files 1937
Total Number of Antennas 128
OPERATIONAL STATUS SUMMARY
Antenna A Priori Status Count dish_maintenance: 3
RF_maintenance: 28
RF_ok: 3
digital_maintenance: 3
digital_ok: 88
not_connected: 3
Commanded Signal Source antenna
Antennas in Commanded State 84 / 128 (65.6%)
Cross-Polarized Antennas 70, 71, 112
Total Number of Nodes 13
Nodes Registering 0s N18
Nodes Not Correlating N05, N13
NIGHTLY ANALYSIS SUMMARY
Ant Metrics Done? ✅
Ant Metrics Flagged Antennas 67 / 128 (52.3%)
Auto Metrics Done? ✅
Auto Metrics Flagged Antennas 83 / 128 (64.8%)
Redcal Done? ✅
Redcal Flagged Antennas 3 / 128 (2.3%)
Never Flagged Antennas 37 / 128 (28.9%)
A Priori Good Antennas Flagged 0 / 0 total a priori good antennas:
A Priori Bad Antennas Not Flagged 37 / 128 total a priori bad antennas:
3, 4, 5, 16, 17, 29, 30, 37, 42, 53, 54, 65,
66, 68, 72, 99, 108, 109, 111, 117, 118, 119,
127, 128, 135, 143, 157, 158, 163, 164, 165,
176, 178, 179, 185, 186, 189
In [19]:
# write to csv
outpath = os.path.join(nb_outdir, f'array_health_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.replace({'\u2705': 'Y'}, regex=True).replace({'\u274C': 'N'}, regex=True).replace({'<br>': ' '}, regex=True).to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/array_health_table_2459764.csv

Build DataFrame¶

In [20]:
# build dataframe
to_show = {'Ant': [f'<a href="{ant_to_report_url(ant)}" target="_blank">{ant}</a>' for ant in ants],
           'Node': [f'N{nodes[ant]:02}' for ant in ants], 
           'A Priori Status': [a_priori_statuses[ant] for ant in ants]}
           #'Worst Metric': worst_metrics, 'Worst Modified Z-Score': worst_zs}
df = pd.DataFrame(to_show)

# create bar chart columns for flagging percentages:
bar_cols = {}
if use_auto_metrics:
    bar_cols['Auto Metrics Flags'] = [float(ant in auto_ex_ants) for ant in ants]
if use_ant_metrics:
    if np.sum(list(a_priori_flag_frac.values())) > 0:  # only include this col if there are any a priori flags
        bar_cols['A Priori Flag Fraction in Ant Metrics'] = [a_priori_flag_frac[ant] for ant in ants]
    for ap in antpols:
        bar_cols[f'Dead Fraction in Ant Metrics ({ap})'] = [dead_ant_frac[ap][ant] for ant in ants]
    bar_cols['Crossed Fraction in Ant Metrics'] = [crossed_ant_frac[ant] for ant in ants]
if use_redcal:
    bar_cols['Flag Fraction Before Redcal'] = [redcal_prior_flag_frac[ant] for ant in ants]
    bar_cols['Flagged By Redcal chi^2 Fraction'] = [redcal_flagged_frac[ant] for ant in ants]  
for col in bar_cols:
    df[col] = bar_cols[col]

# add auto_metrics
if use_auto_metrics:
    for label, modz in all_modzs.items():
        df[label] = modz
z_score_cols = [col for col in df.columns if 'Modified Z-Score' in col]        
        
# add ant_metrics
ant_metrics_cols = {}
if use_ant_metrics:
    for ap in antpols:
        ant_metrics_cols[f'Average Dead Ant Metric ({ap})'] = [average_dead_metrics[ap][ant] for ant in ants]
    ant_metrics_cols['Average Crossed Ant Metric'] = [average_crossed_metrics[ant] for ant in ants]
    for col in ant_metrics_cols:
        df[col] = ant_metrics_cols[col]   

# add redcal chisq
redcal_cols = []
if use_redcal:
    for ap in antpols:
        col_title = f'Median chi^2 Per Antenna ({ap})'
        df[col_title] = [cspa[ant, ap] for ant in ants]
        redcal_cols.append(col_title)

# sort by node number and then by antenna number within nodes
df.sort_values(['Node', 'Ant'], ascending=True)

# style dataframe
table = df.style.hide_index()\
          .applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
          .background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=z_score_cols) \
          .background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=redcal_cols) \
          .applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
          .applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=z_score_cols) \
          .bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
          .format({col: '{:,.4f}'.format for col in z_score_cols}) \
          .format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
          .format({col: '{:,.2%}'.format for col in bar_cols}) \
          .applymap(lambda val: 'font-weight: bold', subset=['Ant']) \
          .set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])

Table 2: RTP Per-Antenna Metrics Summary Table¶

This admittedly very busy table incorporates summary information about all antennas in the array. Its columns depend on what information is available when the notebook is run (i.e. whether auto_metrics, ant_metrics, and/or redcal is done). These can be divided into 5 sections:

Basic Antenna Info: antenna number, node, and its a priori status.

Flag Fractions: Fraction of the night that an antenna was flagged for various reasons. Note that auto_metrics flags antennas for the whole night, so it'll be 0% or 100%.

auto_metrics Details: If auto_metrics is included, this section shows the modified Z-score signifying how much of an outlier each antenna and polarization is in each of four categories: bandpass shape, overall power, temporal variability, and temporal discontinuities. Bold red text indicates that this is a reason for flagging the antenna. It is reproduced from the auto_metrics_inspect.ipynb nightly notebook, so check that out for more details on the precise metrics.

ant_metrics Details: If ant_metrics is included, this section shows the average correlation-based metrics for antennas over the whole night. Low "dead ant" metrics (nominally below 0.4) indicate antennas not correlating with the rest of the array. Negative "crossed ant" metrics indicate antennas that show stronger correlations in their cross-pols than their same-pols, indicating that the two polarizations are probably swapped. Bold text indicates that the average is below the threshold for flagging.

redcal chi^2 Details: If redcal is included, this shows the median chi^2 per antenna. This would be 1 in an ideal array. Antennas are thrown out when they they are outliers in their median chi^2, usually greater than 4-sigma outliers in modified Z-score.

In [21]:
HTML(table.render())
Out[21]:
Ant Node A Priori Status Auto Metrics Flags Dead Fraction in Ant Metrics (Jee) Dead Fraction in Ant Metrics (Jnn) Crossed Fraction in Ant Metrics Flag Fraction Before Redcal Flagged By Redcal chi^2 Fraction ee Shape Modified Z-Score nn Shape Modified Z-Score ee Power Modified Z-Score nn Power Modified Z-Score ee Temporal Variability Modified Z-Score nn Temporal Variability Modified Z-Score ee Temporal Discontinuties Modified Z-Score nn Temporal Discontinuties Modified Z-Score Average Dead Ant Metric (Jee) Average Dead Ant Metric (Jnn) Average Crossed Ant Metric Median chi^2 Per Antenna (Jee) Median chi^2 Per Antenna (Jnn)
3 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.866234 0.179408 1.106345 1.117133 0.199482 1.139574 0.301387 0.936374 0.712912 0.616744 0.401691 4.531273 3.895011
4 N01 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.657724 2.574934 -0.903910 -0.614625 -1.014532 0.061202 1.109285 0.032742 0.726552 0.615688 0.406960 5.880540 4.476793
5 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.146170 -0.216324 0.457811 0.699099 0.060068 1.062494 0.484092 -1.425218 0.729008 0.615385 0.409788 2.531356 2.120136
7 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
8 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
9 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
10 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
15 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.66% -0.227039 0.558241 1.095256 0.006027 1.490621 0.252272 0.824708 0.659763 0.736185 0.627668 0.401333 2.616019 2.351527
16 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.735786 -0.844711 -0.461342 -0.376153 -0.739368 0.065109 0.983004 0.454460 0.738876 0.636352 0.397764 2.753384 2.210669
17 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.904371 -0.154075 0.226173 0.175305 0.083467 0.213043 1.425874 1.326442 0.730219 0.631885 0.402019 2.545408 2.303916
18 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
19 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
20 N02 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
21 N02 digital_ok 100.00% 1.03% 0.52% 0.00% 100.00% 0.00% 1.337958 4.673494 0.768256 7.156626 0.648223 5.197724 0.925212 4.871815 0.698407 0.589455 0.428003 2.670325 2.691919
27 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
28 N01 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
29 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.996097 -0.876609 -0.006027 -0.487726 -0.428226 -0.513048 -0.338493 -0.033275 0.741059 0.644663 0.396404 2.407254 2.359260
30 N01 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.932940 -0.334169 -0.678498 -0.438729 -1.012367 -0.444647 2.747157 -0.163502 0.728167 0.640222 0.397316 2.289106 2.190279
31 N02 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.747452 0.634361 0.727743 1.528497 1.437828 5.725384 1.833131 1.196991 0.730351 0.633186 0.413897 3.612401 3.680472
32 N02 RF_maintenance 100.00% 16.52% 2.07% 0.00% 100.00% 0.00% 37.162770 9.434211 4.513683 0.497830 1.666201 5.843270 20.910899 68.266102 0.618830 0.587843 0.322920 3.287875 3.278149
33 N02 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.292222 0.233952 0.235113 0.000000 0.000000
36 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.335757 7.096842 0.917239 3.830130 1.327552 3.821849 0.736843 1.906665 0.735528 0.632654 0.405119 4.241747 3.792838
37 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 2.620421 2.406306 3.465230 3.378525 2.755578 3.283396 1.147881 2.418904 0.740845 0.633736 0.399980 2.037682 1.939952
38 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 3.224719 3.251177 3.677412 4.007728 5.070038 3.422034 7.423349 -1.314486 0.744258 0.640776 0.402477 4.314003 4.102785
40 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
41 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.32% -0.308697 -1.014189 -0.474541 -0.483212 -0.309304 -0.484001 -0.845663 -0.566112 0.743974 0.656029 0.393366 2.329924 2.100608
42 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.891178 0.522997 -0.959385 0.046583 -1.233105 0.235164 -0.584994 -0.400578 0.744874 0.656880 0.399104 2.436858 2.058585
45 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.011445 0.015687 0.003624 0.000000 0.000000
46 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.288358 0.298825 0.215698 0.000000 0.000000
50 N03 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 2.365900 7.780424 2.989323 0.605993 4.770300 2.964810 31.306414 23.368510 0.731747 0.602097 0.379027 4.635140 4.072736
51 N03 digital_ok 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 0.429997 46.250130 -0.073292 66.829066 -0.457302 9.601246 0.475231 15.035964 0.747629 0.064120 0.475075 3.698537 1.257892
52 N03 RF_maintenance 100.00% 0.00% 100.00% 0.00% 100.00% 0.00% 6.238272 44.536508 -0.242721 64.546237 0.471172 9.962992 6.592232 11.514931 0.727185 0.062216 0.460652 7.925349 1.225950
53 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.181113 0.674428 0.340591 -0.040897 -0.600036 -0.421155 0.449036 3.950734 0.748786 0.666169 0.396292 2.278198 2.024397
54 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.583850 -0.212060 -0.933946 0.405747 -0.739715 1.155566 -0.347444 -0.298123 0.744938 0.659179 0.387635 2.387205 2.242569
55 N04 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 13.211465 5.583882 22.780847 6.720264 19.173592 6.618075 8.536586 -2.551823 0.734241 0.633479 0.405536 3.653645 3.915893
56 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
57 N04 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 7.539339 0.835785 9.618854 2.599162 27.393958 1.994907 4.434863 -1.005958 0.741781 0.642791 0.405891 4.681383 3.723606
65 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.044851 1.894740 1.633784 2.030354 0.610568 1.766159 -1.433695 -1.134948 0.736448 0.637409 0.394773 2.034473 1.737436
66 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.952527 1.072677 3.790270 0.516049 3.685291 0.037411 -2.018056 0.194013 0.742616 0.658697 0.384874 2.007133 1.696699
67 N03 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.595816 6.102732 3.912489 10.724416 5.223846 9.858998 2.015605 6.244019 0.756140 0.675704 0.383446 3.852201 4.526666
68 N03 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.555243 0.044522 0.633467 1.689272 -0.222054 2.070923 -1.135754 0.625685 0.743952 0.671643 0.387595 2.101197 2.003232
69 N04 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
70 N04 RF_maintenance 100.00% 0.00% 0.00% 100.00% 100.00% 0.00% 4.584101 12.077074 1.719319 13.924684 1.736604 19.625690 -0.425430 5.527559 0.336175 0.348012 -0.282917 3.771157 4.195026
71 N04 digital_ok 0.00% 0.00% 0.00% 100.00% 100.00% 0.00% 0.711868 0.242273 1.162307 1.549341 1.834267 1.332957 1.161234 -0.014850 0.345215 0.343730 -0.284574 3.800364 4.007115
72 N04 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 3.051678 -0.466445 1.292505 -0.816466 0.848885 -0.177785 3.061494 -0.621527 0.742138 0.653035 0.403569 1.944956 1.758231
73 N05 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.301309 0.300304 0.212089 0.000000 0.000000
81 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.388105 -0.013175 5.121182 -0.861912 4.483522 -0.207834 8.236561 0.921452 0.737667 0.642295 0.382487 4.437196 3.920594
82 N07 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.778091 0.176542 0.000658 0.830469 -0.451578 0.530876 -0.190311 0.228775 0.746309 0.664169 0.384467 4.408147 3.674967
83 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.463316 6.335342 1.813683 7.631741 4.693128 7.398254 -0.630919 -2.288282 0.748568 0.641246 0.393170 3.721044 3.106516
88 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
89 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
90 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
91 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.436345 25.081762 49.339128 51.064961 10.890545 10.748599 8.986637 8.034718 0.045160 0.048027 0.001098 1.284013 1.708480
92 N10 RF_maintenance 100.00% 49.41% 72.12% 0.00% 100.00% 0.00% 9.618536 14.525259 1.740058 0.946569 7.110298 7.762579 -0.152657 7.052736 0.400300 0.373211 0.174794 4.157066 4.669847
93 N10 digital_ok 100.00% 49.41% 100.00% 0.00% 100.00% 0.00% 7.155796 28.385582 -0.125953 56.677865 6.200218 10.515396 1.617735 10.551858 0.411707 0.065841 0.247305 4.292095 1.309713
94 N10 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.768500 2.747140 1.236220 5.274280 1.672639 5.598555 3.314016 5.483229 0.710349 0.599719 0.413861 4.092234 3.728354
98 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.194455 4.625963 5.478368 1.526837 5.021827 1.601367 -2.037542 2.839709 0.721413 0.642636 0.383877 4.352532 4.426134
99 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.402732 -0.271209 0.709367 -0.924350 -0.037411 1.145290 0.101481 -0.381006 0.741099 0.657987 0.378475 2.331187 1.972832
100 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 5.733557 4.271963 6.806339 5.670230 6.538563 5.562008 -1.031409 -2.404284 0.733015 0.650094 0.390001 3.634368 3.682287
105 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 24.601196 31.597348 49.287446 50.953411 11.027556 10.886545 6.533989 6.036454 0.036335 0.045092 0.008349 1.296242 1.461383
106 N09 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.589457 1.314570 4.714352 2.680625 8.094769 4.201494 3.019371 1.571251 0.740193 0.648894 0.419334 4.550762 3.931396
107 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
108 N09 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.282350 2.618390 1.331613 -0.355832 1.461069 -0.386963 0.241270 -1.037269 0.737712 0.641460 0.408686 1.590641 1.435745
109 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.569309 -1.154002 0.470050 -0.795288 0.742895 -0.495998 0.613181 -0.509190 0.735875 0.639659 0.400686 1.886567 1.716198
110 N10 RF_maintenance 100.00% 6.20% 0.00% 0.00% 100.00% 0.00% 39.827133 6.173163 4.736141 7.336287 5.990844 7.163900 19.446334 -2.485098 0.652667 0.602082 0.336883 5.943452 4.987601
111 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.198443 0.586863 0.048021 -0.826921 0.074400 -0.434941 0.547310 1.572074 0.716351 0.611145 0.406559 1.983701 1.635041
112 N10 digital_ok 0.00% 0.00% 0.00% 100.00% 100.00% 0.00% -1.012687 -0.036704 0.296839 -0.346219 0.068413 1.217350 0.254336 0.163362 0.305148 0.309490 -0.288107 2.935875 2.679758
116 N07 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.172594 5.431000 1.977891 6.721116 0.961130 6.752847 -1.227875 -2.521752 0.726622 0.616855 0.385086 5.510129 5.386646
117 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 1.574129 -0.315668 2.005557 -0.389055 1.558283 -0.069273 -1.700622 -1.185547 0.741985 0.653110 0.387415 2.092198 1.816753
118 N07 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.405010 0.799846 0.079703 -0.012487 -0.758519 -0.111872 0.270586 3.073994 0.750035 0.660961 0.390320 2.315269 2.000822
119 N07 RF_maintenance 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.419078 0.790102 2.195987 0.866357 1.598192 0.615649 -1.735993 -1.496179 0.745920 0.659133 0.404263 3.929312 3.996282
124 N09 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
125 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.109618 25.490735 49.869469 51.232396 10.969100 10.857444 5.357312 9.044767 0.031360 0.033606 0.001858 1.283569 1.289452
126 N09 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 23.756922 26.334002 49.413077 51.569445 10.909717 10.755131 6.881233 8.626323 0.038314 0.036173 -0.000686 1.258857 1.252534
127 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 1.363513 0.960136 1.755726 1.406069 1.200343 1.214162 0.672768 1.355532 0.735761 0.649335 0.391118 5.335939 5.325420
128 N10 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.376139 2.348652 0.210597 -0.697242 0.673824 0.760673 0.014850 -0.490969 0.732868 0.629519 0.392366 2.016129 1.645859
129 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.294248 0.297173 0.207776 0.000000 0.000000
130 N10 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.021610 0.197647 0.115976 0.000000 0.000000
135 N12 digital_maintenance 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -1.235204 -0.745690 -0.563616 -0.944724 -0.941434 -0.680219 1.291188 0.700199 0.723857 0.625618 0.389637 2.225491 1.998622
136 N12 digital_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.391366 9.945022 -0.524839 0.593550 -0.249863 0.474587 1.678136 5.299112 0.732760 0.620472 0.383793 6.500550 7.404827
137 N07 RF_maintenance 100.00% 36.50% 100.00% 0.00% 100.00% 0.00% 10.481713 26.353588 21.185647 49.588902 29.907772 10.602256 6.639277 6.579832 0.417131 0.069679 0.269435 5.632970 1.881383
138 N07 RF_maintenance 100.00% 100.00% 0.00% 0.00% 100.00% 0.00% 26.125018 2.959964 48.355867 3.064367 10.890016 3.157962 4.771145 2.639500 0.058436 0.653070 0.458605 1.268367 3.722055
140 N13 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 1.432083 1.105334 0.462273 0.715800 0.889175 1.568851 0.316013 0.991051 0.085689 0.087423 0.018478 1.251398 1.251599
141 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.257247 8.038547 -0.717151 32.940695 -0.286547 11.048032 0.062427 19.408901 0.077971 0.084155 0.018654 1.282301 1.284536
142 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 28.767472 28.352260 31.424675 55.999358 6.511111 10.444738 6.545440 5.565491 0.091819 0.042289 0.042271 1.365052 1.308093
143 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.020455 -0.973940 -0.813650 -0.697431 -0.840808 -0.362371 -0.662851 -0.709230 0.731976 0.654633 0.404035 1.801885 1.551423
144 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.145594 7.312116 6.747675 9.441367 9.079230 9.041040 3.378134 2.723118 0.740142 0.656129 0.407987 6.903929 6.410762
145 N14 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 22.103722 25.071373 55.375855 56.360502 10.624239 10.459526 7.494780 7.385743 0.047822 0.049521 -0.000850 1.444341 1.411179
150 N15 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
155 N12 digital_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.662716 23.758451 54.356132 55.678746 10.440240 10.318547 8.298329 8.460194 0.062755 0.059811 0.001907 1.405547 1.486840
156 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.432477 -0.245539 -0.397078 0.739408 -0.449570 4.848790 0.102252 10.054881 0.731368 0.618225 0.399098 6.241482 4.561370
157 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.173743 -0.459897 1.812104 -0.193294 0.811690 -0.258482 -1.346394 0.623931 0.728868 0.632454 0.395692 4.998741 4.104460
158 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 100.00% 0.00% -1.052268 -1.749633 -0.670483 -0.349927 -0.211119 0.138461 -0.505087 0.742198 0.733658 0.637879 0.399373 4.951709 4.192448
160 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 21.639340 24.902717 54.628087 55.797832 10.627919 10.432553 5.103989 5.754541 0.043059 0.042753 0.001819 1.221374 1.219237
161 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.410304 55.401711 3.102661 14.020369 3.141869 5.847184 1.514488 4.003392 0.047480 0.055530 0.003779 1.248084 1.247625
162 N13 digital_ok 0.00% 100.00% 100.00% 0.00% 100.00% 0.00% 0.220762 -0.508504 0.194666 -0.906676 -0.376938 -0.332951 -0.134133 -0.676214 0.067115 0.059932 0.004346 1.235143 1.223178
163 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.192296 -0.221169 0.319468 -0.843131 0.289550 -0.837611 -0.196084 -0.103816 0.733807 0.647339 0.404938 2.282829 2.155398
164 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.604730 -1.122393 -0.597981 -0.601411 -1.024582 0.942107 0.995321 1.485556 0.733712 0.645697 0.400103 2.398341 2.167578
165 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.710358 -0.312663 0.011315 -0.893579 0.975269 -0.939237 2.290094 -0.354349 0.733987 0.646620 0.391704 2.623748 2.609940
166 N14 RF_maintenance 100.00% 3.61% 0.00% 0.00% 100.00% 0.00% 28.904851 20.558415 5.183037 3.940376 1.709894 4.690861 11.192153 42.279819 0.636766 0.554203 0.247358 4.147340 3.485949
167 N15 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
168 N15 RF_maintenance 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 4.066827 6.239822 4.465115 7.128817 4.088915 6.945368 -1.475160 -2.265384 0.707160 0.600330 0.390002 5.039868 4.066380
169 N15 digital_ok 100.00% 1.55% 1.55% 0.00% 100.00% 0.00% 5.651523 5.116898 6.460384 5.804716 5.967903 5.734530 -2.291729 -1.534635 0.695683 0.588790 0.390012 4.882756 3.855093
170 N15 digital_ok 100.00% 3.10% 1.55% 0.00% 100.00% 0.00% 5.993301 3.639439 6.724917 4.855971 6.435370 4.685869 -1.788760 -1.644373 0.681546 0.589084 0.394900 5.123560 4.383833
176 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.284816 -1.059494 0.346789 -0.331353 -0.461756 -0.119490 -1.154289 -0.323558 0.714684 0.609436 0.405656 1.799693 1.524897
177 N12 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% -0.129843 1.802935 -0.035156 2.133542 0.308580 15.868603 0.367085 1.772462 0.720203 0.600882 0.409159 5.657528 5.347249
178 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.756979 -1.430154 2.739103 -0.501946 2.917166 -0.352686 0.929136 1.109887 0.726212 0.625336 0.404757 1.607412 1.361765
179 N12 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.980120 0.551751 -0.219483 -0.196512 -0.407164 -0.311217 -0.016439 -0.698240 0.723962 0.628940 0.408826 1.580626 1.405382
180 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 31.898357 26.815124 5.557055 56.359109 16.453202 10.532808 207.315127 6.157080 0.096601 0.042467 0.041760 1.259894 1.211763
181 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 6.898185 1.852980 8.433851 2.333120 9.065245 2.804809 2.863385 1.251697 0.055450 0.059395 0.006506 1.250503 1.250989
182 N13 RF_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 2.805080 1.698290 4.142599 3.289002 3.309213 14.078637 -1.998101 2.191501 0.084329 0.072171 0.008020 1.221308 1.220197
183 N13 digital_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% -0.140746 1.601965 1.779634 3.422552 1.443351 4.107158 0.732702 7.531379 0.067153 0.055207 0.005946 1.219197 1.213815
184 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 1.99% 0.502236 -0.020455 -0.222596 0.265903 -0.523563 -0.197745 0.084258 -0.130223 0.730605 0.630769 0.406923 2.571076 2.430165
185 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% -0.393192 -0.590204 -0.887775 -0.917639 -1.420088 -0.928437 -0.747890 -0.807154 0.731445 0.637691 0.400482 2.441627 2.231510
186 N14 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.278678 -0.109548 -0.719949 -0.724192 -0.577362 -0.733737 0.654556 -0.550278 0.724930 0.631470 0.394896 2.395395 2.310919
187 N14 digital_ok 100.00% 0.00% 0.00% 0.00% 100.00% 0.00% 0.562062 2.805572 0.094475 3.754637 -0.409644 3.602800 2.389632 56.047121 0.722768 0.638433 0.389870 5.098558 5.332092
189 N15 digital_ok 0.00% 0.00% 0.00% 0.00% 0.00% 0.00% 0.700703 1.785924 -0.847257 0.334448 -0.675157 0.687833 -0.452746 -1.250221 0.706402 0.606211 0.398792 1.983990 1.625132
190 N15 digital_ok 100.00% 18.07% 20.13% 0.00% 100.00% 0.00% 44.019194 57.278699 7.194404 10.535962 3.049714 6.121491 58.036045 107.489958 0.575349 0.500891 0.257211 5.451679 5.764467
191 N15 digital_ok 0.00% 3.10% 1.55% 0.00% 1.32% 0.00% 0.134757 -0.674554 1.120160 -0.941515 0.152518 -0.945373 -1.275697 -0.716148 0.689914 0.591986 0.404588 1.615223 1.445865
220 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
221 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
222 N18 RF_ok 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan nan nan nan 0.000000 0.000000
320 N03 dish_maintenance 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% 29.880215 28.662863 43.404635 43.626568 10.457081 10.234452 8.401367 6.218689 0.082184 0.078673 -0.000050 0.000000 0.000000
321 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.237182 0.248867 0.202278 0.000000 0.000000
323 N02 not_connected 100.00% 100.00% 100.00% 0.00% 100.00% 0.00% nan nan inf inf nan nan nan nan 0.184321 0.239566 0.190887 0.000000 0.000000
324 N04 not_connected 100.00% 19.62% 40.78% 0.00% 100.00% 0.00% 6.487435 7.093169 7.538571 7.974827 7.303458 7.729478 -1.812098 -2.792862 0.607058 0.446126 0.382930 0.000000 0.000000
329 N12 dish_maintenance 100.00% 16.00% 35.62% 0.00% 100.00% 0.00% 0.311057 3.633238 0.819104 4.886771 4.527309 4.777971 1.496175 -2.063984 0.629562 0.472482 0.393931 0.000000 0.000000
333 N12 dish_maintenance 100.00% 17.04% 37.17% 0.00% 100.00% 0.00% 5.005722 1.826412 7.176017 2.526266 4.663105 3.026802 5.918625 -0.849518 0.611566 0.466165 0.378728 0.000000 0.000000
In [22]:
# print ex_ants for easy copy-pasting to YAML file
proposed_ex_ants = [ant for i, ant in enumerate(ants) if np.any([col[i] > 0 for col in bar_cols.values()])]
print('ex_ants: [' + ", ".join(str(ant) for ant in proposed_ex_ants) + ']')
print(f'\nunflagged_ants: [{", ".join([str(ant) for ant in ants if ant not in proposed_ex_ants])}]')
# "golden" means no flags and good a priori status
golden_ants = ", ".join([str(ant) for ant in ants if ((ant not in proposed_ex_ants) and (a_priori_statuses[ant] in good_statuses.split(',')))])
print(f'\ngolden_ants: [{golden_ants}]')
ex_ants: [3, 4, 7, 8, 9, 10, 15, 18, 19, 20, 21, 27, 28, 31, 32, 33, 36, 38, 40, 41, 45, 46, 50, 51, 52, 55, 56, 57, 67, 69, 70, 71, 73, 81, 82, 83, 88, 89, 90, 91, 92, 93, 94, 98, 100, 105, 106, 107, 110, 112, 116, 119, 124, 125, 126, 127, 129, 130, 136, 137, 138, 140, 141, 142, 144, 145, 150, 155, 156, 157, 158, 160, 161, 162, 166, 167, 168, 169, 170, 177, 180, 181, 182, 183, 184, 187, 190, 191, 220, 221, 222, 320, 321, 323, 324, 329, 333]

unflagged_ants: [5, 16, 17, 29, 30, 37, 42, 53, 54, 65, 66, 68, 72, 99, 108, 109, 111, 117, 118, 128, 135, 143, 163, 164, 165, 176, 178, 179, 185, 186, 189]

golden_ants: []
In [23]:
# write to csv
outpath = os.path.join(nb_outdir, f'rtp_summary_table_{JD}.csv')
print(f'Now saving Table 2 to a csv at {outpath}')
df.to_csv(outpath)
Now saving Table 2 to a csv at /home/obs/src/H5C_Notebooks/_rtp_summary_/rtp_summary_table_2459764.csv
In [24]:
# Load antenna positions
data_list = sorted(glob.glob(os.path.join(data_path, f'zen.{JD}.?????.sum.uvh5')))
hd = io.HERAData(data_list[len(data_list) // 2])

# Figure out where to draw the nodes
node_centers = {}
for node in sorted(set(list(nodes.values()))):
    if np.isfinite(node):
        this_node_ants = [ant for ant in ants + unused_ants if nodes[ant] == node]
        if len(this_node_ants) == 1:
            # put the node label just to the west of the lone antenna 
            node_centers[node] = hd.antpos[ant][node] + np.array([-14.6 / 2, 0, 0])
        else:
            # put the node label between the two antennas closest to the node center
            node_centers[node] = np.mean([hd.antpos[ant] for ant in this_node_ants], axis=0)
            closest_two_pos = sorted([hd.antpos[ant] for ant in this_node_ants], 
                                     key=lambda pos: np.linalg.norm(pos - node_centers[node]))[0:2]
            node_centers[node] = np.mean(closest_two_pos, axis=0)
In [25]:
def Plot_Array(ants, unused_ants, outriggers):
    plt.figure(figsize=(16,16))
    
    plt.scatter(np.array([hd.antpos[ant][0] for ant in hd.data_ants if ant in ants]), 
                np.array([hd.antpos[ant][1] for ant in hd.data_ants if ant in ants]), c='w', s=0)

    # connect every antenna to their node
    for ant in ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', zorder=0)

    rc_color = '#0000ff'
    antm_color = '#ffa500'
    autom_color = '#ff1493'

    # Plot 
    unflagged_ants = []
    for i, ant in enumerate(ants):
        ant_has_flag = False
        # plot large blue annuli for redcal flags
        if use_redcal:
            if redcal_flagged_frac[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=7 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=rc_color, alpha=redcal_flagged_frac[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot medium green annuli for ant_metrics flags
        if use_ant_metrics: 
            if ant_metrics_xants_frac_by_ant[ant] > 0:
                ant_has_flag = True
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=6 * (2 - 1 * float(not outriggers)), fill=True, lw=0,
                                                color=antm_color, alpha=ant_metrics_xants_frac_by_ant[ant]))
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, color='w'))
        
        # plot small red annuli for auto_metrics
        if use_auto_metrics:
            if ant in auto_ex_ants:
                ant_has_flag = True                
                plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=5 * (2 - 1 * float(not outriggers)), fill=True, lw=0, color=autom_color)) 
        
        # plot black/white circles with black outlines for antennas
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4 * (2 - 1 * float(not outriggers)), fill=True, color=['w', 'k'][ant_has_flag], ec='k'))
        if not ant_has_flag:
            unflagged_ants.append(ant)

        # label antennas, using apriori statuses if available
        try:
            bgc = matplotlib.colors.to_rgb(status_colors[a_priori_statuses[ant]])
            c = 'black' if (bgc[0]*0.299 + bgc[1]*0.587 + bgc[2]*0.114) > 186 / 256 else 'white'
        except:
            c = 'k'
            bgc='white'
        plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color=c, backgroundcolor=bgc)

    # label nodes
    for node in sorted(set(list(nodes.values()))):
        if not np.isnan(node) and not np.all(np.isnan(node_centers[node])):
            plt.text(node_centers[node][0], node_centers[node][1], str(node), va='center', ha='center', bbox={'color': 'w', 'ec': 'k'})
    
    # build legend 
    legend_objs = []
    legend_labels = []
    
    # use circles for annuli 
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgecolor='k', markerfacecolor='w', markersize=13))
    legend_labels.append(f'{len(unflagged_ants)} / {len(ants)} Total {["Core", "Outrigger"][outriggers]} Antennas Never Flagged')
    legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='k', markersize=15))
    legend_labels.append(f'{len(ants) - len(unflagged_ants)} Antennas {["Core", "Outrigger"][outriggers]} Flagged for Any Reason')

    if use_auto_metrics:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=autom_color, markersize=15))
        legend_labels.append(f'{len([ant for ant in auto_ex_ants if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas Flagged by Auto Metrics')
    if use_ant_metrics: 
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=antm_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum([frac for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants]), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in ant_metrics_xants_frac_by_ant.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Ant Metrics\n(alpha indicates fraction of time)')        
    if use_redcal:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markeredgewidth=2, markeredgecolor=rc_color, markersize=15))
        legend_labels.append(f'{np.round(np.sum(list(redcal_flagged_frac.values())), 2)} Antenna-Nights on' 
                             f'\n{np.sum([frac > 0 for ant, frac in redcal_flagged_frac.items() if ant in ants])} {["Core", "Outrigger"][outriggers]} Antennas '
                             'Flagged by Redcal\n(alpha indicates fraction of time)')

    # use rectangular patches for a priori statuses that appear in the array
    for aps in sorted(list(set(list(a_priori_statuses.values())))):
        if aps != 'Not Found':
            legend_objs.append(plt.Circle((0, 0), radius=7, fill=True, color=status_colors[aps]))
            legend_labels.append(f'A Priori Status:\n{aps} ({[status for ant, status in a_priori_statuses.items() if ant in ants].count(aps)} {["Core", "Outrigger"][outriggers]} Antennas)')

    # label nodes as a white box with black outline
    if len(node_centers) > 0:
        legend_objs.append(matplotlib.patches.Patch(facecolor='w', edgecolor='k'))
        legend_labels.append('Node Number')

    if len(unused_ants) > 0:
        legend_objs.append(matplotlib.lines.Line2D([0], [0], marker='o', color='w', markerfacecolor='grey', markersize=15, alpha=.2))
        legend_labels.append(f'Anntenna Not In Data')
        
    
    plt.legend(legend_objs, legend_labels, ncol=2, fontsize='large', framealpha=1)
    
    if outriggers:
        pass
    else:
        plt.xlim([-200, 150])
        plt.ylim([-150, 150])        
       
    # set axis equal and label everything
    plt.axis('equal')
    plt.tight_layout()
    plt.title(f'Summary of {["Core", "Outrigger"][outriggers]} Antenna Statuses and Metrics on {JD}', size=20)    
    plt.xlabel("Antenna East-West Position (meters)", size=12)
    plt.ylabel("Antenna North-South Position (meters)", size=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    xlim = plt.gca().get_xlim()
    ylim = plt.gca().get_ylim()    
        
    # plot unused antennas
    plt.autoscale(False)    
    for ant in unused_ants:
        if nodes[ant] in node_centers:
            plt.plot([hd.antpos[ant][0], node_centers[nodes[ant]][0]], 
                     [hd.antpos[ant][1], node_centers[nodes[ant]][1]], 'k', alpha=.2, zorder=0)
        
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='w', ec=None, alpha=1, zorder=0))
        plt.gca().add_artist(plt.Circle(tuple(hd.antpos[ant][0:2]), radius=4, fill=True, color='grey', ec=None, alpha=.2, zorder=0))
        if hd.antpos[ant][0] < xlim[1] and hd.antpos[ant][0] > xlim[0]:
            if hd.antpos[ant][1] < ylim[1] and hd.antpos[ant][1] > ylim[0]:
                plt.text(hd.antpos[ant][0], hd.antpos[ant][1], str(ant), va='center', ha='center', color='k', alpha=.2) 

Figure 1: Array Plot of Flags and A Priori Statuses¶

This plot shows all antennas, which nodes they are connected to, and their a priori statuses (as the highlight text of their antenna numbers). It may also show (depending on what is finished running):

  • Whether they were flagged by auto_metrics (red circle) for bandpass shape, overall power, temporal variability, or temporal discontinuities. This is done in a binary fashion for the whole night.
  • Whether they were flagged by ant_metrics (green circle) as either dead (on either polarization) or crossed, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.
  • Whether they were flagged by redcal (blue circle) for high chi^2, with the transparency indicating the fraction of the night (i.e. number of files) that were flagged.

Note that the last fraction does not include antennas that were flagged before going into redcal due to their a priori status, for example.

In [26]:
core_ants = [ant for ant in ants if ant < 320]
outrigger_ants = [ant for ant in ants if ant >= 320]
Plot_Array(ants=core_ants, unused_ants=unused_ants, outriggers=False)
if len(outrigger_ants) > 0:
    Plot_Array(ants=outrigger_ants, unused_ants=sorted(set(unused_ants + core_ants)), outriggers=True)

Metadata¶

In [27]:
from hera_qm import __version__
print(__version__)
from hera_cal import __version__
print(__version__)
2.0.4.dev8+g8ce4cac
3.1.5.dev74+gf9d2808
In [ ]: